<?php
include 'lanewechat.php';
if( !empty( $_POST ) ){
	try{
    \LaneWeChat\Core\Common::getJsPay( $_POST['openid'] , $_POST['money'] , $_POST['num']  ); }
	catch( Exception $e ){
		var_dump( $e->getMessage() );die;
	}
}
$result = \LaneWeChat\Core\Common::getCurrentCardInfo( $_GET['openid'] );
?>
<!DOCTYPE html>
<html>
<head>
    <title>鹏企科技</title>
    <meta name="keywords" content="鹏企科技">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1,initial-scale=1.0, maximum-scale=1.0,user-scalable=0">
    <meta name="renderer" content="webkit">
    <link rel=Stylesheet type="text/css" href="css/common.css">
    <link rel=Stylesheet type="text/css" href="css/style.css">
</head>

<body data-openid="<?=$_GET['openid']?>" >


<div class="container">

    <div class="header" onclick="history.go(-1)"><img src="images/arrow.png">充值</div>

    <div class="container2 count">
        <p>账户余额（元）<font><?=$result['SumCash']/100?></font></p>
        <p>账户余次（次）<font>0</font></p>
    </div>

    <div class="container2 recharge-info">
        <p><span>手机：</span><?=$result['Phone']?> </p>
        <p><span>卡号：</span><?=$result['CardNo']?></p>
    </div>

<form method="post">
    <input type="hidden" name="code" id="openid" value="<?=$_GET['openid']?>">
    <div class="container2 recharge">

        <div class="recharge-sel">
            <p class="title">选择金额：</p>
            <p>
                <a href="javascript:void(0)" class="gdje" data-money="100">100元</a>
                <a href="javascript:void(0)" class="gdje" data-money="50">50元</a>
                <a href="javascript:void(0)" class="gdje" data-money="500">500元</a>
                <a href="javascript:void(0)" class="gdje" data-money="200">200元</a>
                <input name="money" id="money" type="text" placeholder="输入您想充值的金额">
            </p>
        </div>

        <div class="clearfix"></div>

        <div class="recharge-sel2">
            <p class="title">充值次数：</p>
            <p>
                <input name="num" id="num" value="1" type="number" placeholder="输入您想充值的次数">
            </p>
        </div>

        <div><input onclick="recharge()" type="button" value="充值" class="btn"></div>
        <div class="lk-click"><a href="reportDetail.php?id=Rpt_Vip_Log2&openid=<?=$_GET['openid']?>">点此查看充值记录</a></div>

    </div>
</form>

    <div class="footer"><img src="images/logo.png">本服务由上海鹏企自动化科技有限公司提供</div>

</div>



<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script>
    $('.gdje').click(function(){
        var money = parseInt( $(this).attr('data-money') );
        $('#money').val( money );
        $('#num').val(1);
        recharge();
    });
    function recharge(){
        var money = parseFloat( $('#money').val() );
        var num = parseInt( $('#num').val() );
        if( $('#money').val() == '' || money <= 0 ){
            alert('充值金额错误~');
            return;
        }
        $.ajax({
            url:'recharge.php',
            data:{
                money:money,
                openid:$('body').attr('data-openid'),
                num:num
            },
            dataType:'json',
            error:function(){
            },
            type:'post'
        }).done(function(data){
            if( data.error == 0 ){
                jsApiParams = JSON.parse( data.data.js );
                jsApiAddress = JSON.parse( data.data.address );
                callpay();
            }
        })
    }
    var jsApiParams = {};
    function jsApiCall()
    {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',
            jsApiParams,
            function(res){
                if(res.err_msg=='get_brand_wcpay_request:ok'){
					alert('支付成功!');
                    window.location.href='/app/index.php?i=2&c=entry&do=orderdetail&m=weisrc_dish&otherurl=query';
                }
				else{
					alert('支付失败!');
				}
                return false;
            }
        );
    }

    function callpay()
    {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall();
        }
    }
    var jsApiAddress = {};
    //获取共享地址
    function editAddress()
    {
        WeixinJSBridge.invoke(
            'editAddress',
            jsApiAddress,
            function(res){
                var value1 = res.proviceFirstStageName;
                var value2 = res.addressCitySecondStageName;
                var value3 = res.addressCountiesThirdStageName;
                var value4 = res.addressDetailInfo;
                var tel = res.telNumber;

                //alert(value1 + value2 + value3 + value4 + ":" + tel);
            }
        );
    }
    var addressShare = function(){
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', editAddress, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', editAddress);
                document.attachEvent('onWeixinJSBridgeReady', editAddress);
            }
        }else{
            editAddress();
        }
    };
    $('.recharge-sel a').click(function(){
        $('.recharge-sel a').removeClass('on');
        $(this).addClass('on');
    });
</script>
</body>
</html>